<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 停课 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-contract"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 停课原因 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header bg-gold">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 停课信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-stopinfo">
				<form class="form-horizontal form-editor form-editor-stopinfo">
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="createDate">处理时间</label>
								<div class="col-sm-8">
									<div class="input-group date date-selector">
										<input name="createDate" id="createDate" type="text" class="form-control"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div> 
								</div>
							</div>
						</div>
						<div class="col-sm-8">
							<div class="form-group">
								<label class="col-sm-2 control-label" for="fromDate">停课时间</label>
								<div class="col-sm-8">
									<div class="input-group date">
										<input name="fromDate" type="text" class="form-control date-selector">
										<span class="input-group-addon no-border-radius">－</span>
										<input name="overDate" type="text" class="form-control date-selector">
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="username">处理人</label>
								<div class="col-sm-8">
									<input type="text" name="username" id="username" class="form-control" readonly="readonly" /> 
									<input type="hidden" name="userid" id="userid" data-default-user/>
								</div>
							</div>
						</div>
						<div class="col-sm-8">
							<div class="form-group">
								<label class="col-sm-2 control-label" for="reason">停课原因</label>
								<div class="col-sm-8">
									<select name="reason" id="reason" class="chosen-select" data-url="/miwawa/default/common/select.json" data-pcode="c_pause_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
									</select> 
								</div>
							</div>
						</div>
					</div>
				
					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-contract">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" 
										onclick="handlerSubmit(this, '#editor-form-stopinfo', '.form-editor-stopinfo');" 
										data-submit-callback="updateContract">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-contract">
				
			</div>
		</div>
		
		<!-- TODO 购买信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-buyinfo">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 购买信息 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-buyinfo">
				
			</div>
		</div>
		
		<!-- TODO 付款信息 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-payinfo">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 付款信息 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm editor-body-payinfo">
				
			</div>
		</div>
		
		<!-- TODO 购买历史 -->
		<div class="widget radius-bordered mgbt-xs-10" id="editor-panel-history">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 购买历史 </a> </span>
				<div class="widget-buttons compact">
					<a href="" data-toggle="collapse"> <i class="fa fa-expand"></i> </a> 
				</div>
			</div>
			<div class="widget-body editor-body-sm">
				<table data-ajax="handlerSearch" data-method="post"
							 data-id-field="id" 
							 data-unique-id="id" 
							 data-pagination="true"  
							 data-check-on-init="true" 
							 data-side-pagination="server" 
							 data-mobile-responsive="true"
							 data-form-search="#search-form-history" id="table-history">
					<thead>
						<tr>
							<th data-checkbox="true"></th>
							<th data-field="student" 		data-align="center">宝宝姓名</th>
							<th data-field="item" 			data-align="center">购买项目</th>
							<th data-field="type" 			data-align="center">项目类型</th>
							<th data-field="createDate" data-align="center">购买时间</th>
							<th data-field="fromDate" 	data-align="center">起止时间</th>
							<th data-field="totals" 		data-align="center">总金额</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-stopinfo" action="/{dbname}/contract/stop/{studentid}" method="post" 
			name="com.app.miwawa.api.esm.entity.contract.Stopinfo"
			data-custom-action="true">
			<input type="hidden" name="status" value="0">
			<input type="hidden" name="invalid" value="F">
			<input type="hidden" name="contractId" data-foreign-id>
</form>

<script type="text/javascript">
<!--
	require(['domReady'],function(domReady){
		domReady(function () {
			jQuery("#search-form-buyinfo").data("template-id","#view-buyinfo-template");
			jQuery("#search-form-payinfo").data("template-id","#view-payinfo-template");
			require(['jquery.plugin.form'],function(form){
				form.chosen("#reason").select("#reason");
			});
			initData();
		});
	});
	
	var contract;
	function initData(){
		contract = jQuery("#table-contract").data("selectedRow");
		jQuery("#userid",".form-editor-stopinfo").val(userid);
		jQuery("#username",".form-editor-stopinfo").val(username);
		jQuery(":hidden[name='contractId'],[data-foreign-id]").val(contract.id);
		jQuery(":hidden[name='studentid']").val(contract.studentid);
		jQuery("#editor-form-stopinfo").attr("action","/miwawa/{dbname}/contract/stop/{studentid}".replace("{studentid}",contract.studentid));
				
		jQuery(".editor-body-contract").loadform("load", {
			templateId: "#view-contract-template",
			templatePath: "/miwawa/content/esm/contract/template.html",
			templateData: contract
		});
		
		jQuery("#search-form-buyinfo").loadform("many",helperBuyinfo());
		
	 	jQuery("#search-form-payinfo").loadform("many");
	 	
		jQuery("#table-history").bootstrapTable({
			onLoadSuccess:function(data){
				require(['jquery.plugin.form'],function(form){
					form.datepicker(".date-selector");
					form.tooltip("[data-toggle='tooltip']");
				});
			}
		});
	}
	
	// 更新合同状态
	function updateContract(){
		jQuery.ajaxsend({
			url:"/miwawa/{dbname}/common/update".replace("{dbname}", dbname),
			data:{
				"entityClass":"com.app.miwawa.api.esm.entity.contract.Contract",
				"bean":{
					"id":contract.id,
					"status":"pause"
				}
			},
			success:function(data){
				if(data && !data.error){
					jQuery.ajaxsend({
						url:"/miwawa/{dbname}/common/search.json".replace("{dbname}", dbname),
						data:{
							"entityClass":"com.app.miwawa.api.eam.entity.StudentLeaveLimit",
							"and[0][operator]": "EQ",
					    "and[0][fieldName]": "contractId",					
					    "and[0][fieldValue]": contract.id
						},
						success:function(data){
							if(data && !data.error){
								jQuery('[data-toggle="dispose"]')[0].click();
								var limits = data.rows;
								for(var i=0;i<limits.length;i++){
									jQuery.ajaxsend({
				 						url:"/miwawa/{dbname}/common/remove".replace("{dbname}", dbname),
				 						data:{
				 			 				"entityClass":"com.app.miwawa.api.eam.entity.StudentLeaveLimit",
				 			 				"bean":{
				 			 					"id":limits[i].id
				 			 				},
				 			 				success:function(data){
				 								if(data && !data.error){
				 									jQuery('[data-toggle="dispose"]')[0].click();
				 								}
				 							}
				 			 			}
				 					});
								}
							}
						}
					});
				}
			}
		});
	}
//-->
</script>